<?php
namespace App\Service\ApiApp;

class MapService extends BaseService
{
    //地图

    //列表
    public static function index()
    {
        $rows = self::dbConn(self::$dbShelf)
            ->where('is_able', 0)
            ->where('pid', 0)
            ->orderBy('xuhao', 'asc')
            ->get();
        if (!count($rows)) {
            return self::toback(-2, '没有数据');
        }
        $arys = [];
        foreach ($rows as $v) {
            $shelfOnes = self::dbConn(self::$dbShelf)
                ->where('is_able', 0)
                ->where('xuhao', $v->xuhao)
                ->get();
                $shelfList = [];
            if (count($shelfOnes)) {
                foreach ($shelfOnes as $vv) {
                    $shelfList[] = [
                        'id' => $vv->id, 'title' => $vv->title,
                        'type' => $vv->type,
                    ];
                }
            }
            $arys[] = [
                'id' => $v->id, 'title' => $v->title,
                'type' => $v->type, 'childs' => $shelfList,
            ];
        }
        return self::toback(0, '', $arys);
    }
}